//
//  UIView+LxViewFrame.m
//  LvXiMark
//
//  Created by apple on 16/4/22.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "UIView+LxViewFrame.h"

@implementation UIView (LxViewFrame)


-(void)setWidth:(CGFloat)width{
    CGRect rect = self.frame;
    rect.size.width = width;
    self.frame = rect;
    
}

-(void)setHeight:(CGFloat)height{
    CGRect rect = self.frame;
    rect.size.height = height;
    self.frame = rect;
}

-(void)setX:(CGFloat)x{
    CGRect rect = self.frame;
    rect.origin.x = x;
    self.frame = rect;
}

-(void)setY:(CGFloat)y{
    CGRect rect = self.frame;
    rect.origin.y = y;
    self.frame = rect;
}


-(void)setCenterX:(CGFloat)centerX{
    CGRect rect = self.frame;
    rect.origin.x = centerX -  self.width * 0.5;
    self.frame = rect;
}

-(void)setCenterY:(CGFloat)centerY{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}

-(void)setTop:(CGFloat)top{
    CGRect rect = self.frame;
    rect.origin.y = top;
    self.frame = rect;
}

-(void)setBotton:(CGFloat)botton{
    CGRect rect = self.frame;
    rect.origin.y = botton-rect.size.height;
    self.frame = rect;
}

-(void)setLeft:(CGFloat)left{
    CGRect rect = self.frame;
    rect.origin.x = left;
    self.frame = rect;
}

-(void)setRight:(CGFloat)right{
    CGRect rect = self.frame;
    rect.origin.x = self.superview.width-right-self.width;
    self.frame = rect;
}

-(void)setSize:(CGSize)size{
    CGRect rect = self.frame;
    rect.size = size;
    self.frame = rect;
}

-(CGFloat)width{
    return self.frame.size.width;
}

-(CGFloat)height{
    return self.frame.size.height;
}

-(CGFloat)x{
    return self.frame.origin.x;
}

-(CGFloat)y{
    return self.frame.origin.y;
}

-(CGFloat)centerX{
    return self.x  + self.width*0.5;
}

-(CGFloat)centerY{
    return self.center.y;
}

-(CGFloat)top{
    return self.frame.origin.y;
}

-(CGFloat)botton{
    return CGRectGetMaxY(self.frame);
}

-(CGFloat)left{
    return self.frame.origin.x;
}


-(CGFloat)right{
    return CGRectGetMaxX(self.frame);
}

-(CGSize)size{
    return self.frame.size;
}

-(void)addRadius:(CGFloat)radius;{
    self.layer.cornerRadius = radius;
    self.layer.masksToBounds = YES;
}

-(void)setRadius:(CGFloat)radius{
    [self addRadius:radius];
}
-(CGRect)frameFrom:(CGSize)size inFrame:(CGRect)frame{
    CGFloat x = (CGRectGetWidth(frame) - size.width)*0.5;
    CGFloat y = (CGRectGetHeight(frame) - size.height)*0.5;
    return CGRectMake(x, y, size.width, size.height);
}

-(void)addGradientLayerWithColors:(NSArray *)colors starPoint:(CGPoint)starPoint endPoint:(CGPoint)endPoint{

    //设置背景色渐变
    CAGradientLayer * gradientLayer = [CAGradientLayer layer];
    gradientLayer.bounds = self.bounds;
    gradientLayer.borderWidth = 0;
    gradientLayer.frame = self.bounds;
    gradientLayer.colors = colors;
    gradientLayer.startPoint = starPoint;
    gradientLayer.endPoint = endPoint;
    [self.layer insertSublayer:gradientLayer atIndex:0];
}

@end
